package com.el.logger;

import java.util.List;
import java.util.Map;


public class EventLogDispatcher {
    private List<ELogger> loggers;
    
    public void log(String id, Action type, Map<String, String> params, Throwable t) {
        
        long timestamp = System.nanoTime();
        long threadId = Thread.currentThread().getId();
        
        if (loggers != null) {
            for (ELogger logger : loggers) {
                logger.log(createEntry(timestamp, threadId, id, type, params, t));
            }
        }
    }
    
    private EventLogEntry createEntry(long timestamp, long threadId, String id, Action action, Map<String, String> params, Throwable t) {
        EventLogEntry result = new EventLogEntry();
        
        result.setEventId(id);
        result.setAction(action);
        result.setException(t);
        result.setHostName(null);
        result.setParams(params);
        result.setThreadId(threadId);
        result.setTimestamp(timestamp);
        
        return result;
    }

    public void setLogs(List<ELogger> loggers) {
        this.loggers = loggers;
    }
}
